package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrdersService ordersService;
    /**
     * 查询订单详情（订单id）
     *
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Integer id) {
        OrderVO orderVo = ordersService.orderDetail(id);
        return Result.success(orderVo);
    }

    /**
     * 完成订单
     *
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Integer id) {
        ordersService.complete(id);
        return Result.success();
    }

    /**
     * 取消订单
     *
     * @param dto
     * @return
     */
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto) {
        ordersService.adminCancel(dto);
        return Result.success();
    }

    /**
     * 拒单
     *
     * @param dto
     * @return
     */
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) {
        ordersService.rejection(dto);
        return Result.success();
    }
    /**
     * 接单
     *
     * @param id
     * @return
     */
    @PutMapping("/confirm")
    public Result confirm(@RequestBody Integer id) {
        ordersService.confirm(id);
        return Result.success();
    }
    /**
     * 订单搜索
     *
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto) {
        PageResult result = ordersService.conditionSearch(dto);
        return Result.success(result);
    }

    /**
     * 派送订单
     *
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable Integer id) {
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 各个状态的订单数量统计
     *
     *
     * @return
     */
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        OrderStatisticsVO vo = ordersService.statistics();
        return Result.success(vo);
    }


}
